#include "Task.h"

#include <QRegularExpression>
#include<QDebug>
Task::Task()
{
}

void Task::taskSort(QString str)
{qDebug()<<"str:"<<str<<endl;
    QRegularExpression reg1("(?<=\;)[^;:]*?(?=\:)");
    QRegularExpressionMatchIterator iterKey = reg1.globalMatch(str);
    QRegularExpression reg2("(?<=\:)[^;:]*?(?=\;)");
    QRegularExpressionMatchIterator iterValue = reg2.globalMatch(str);
    QMap<QString,QString> kv;
    while (iterKey.hasNext() && iterValue.hasNext())
    {
        kv.insert(iterKey.next().captured(0),iterValue.next().captured(0));
    }
    qDebug()<<"kv:"<<kv<<endl;
    switch (kv.value("function").toInt()) {
    case 1:
        F01(kv);//登陆状态
            break;
    case 2:
        F02(kv);//进入排队页面
        break;
    case 3:
        F03(kv);
        break;
    case 4:
        emit this->sendMainMenuData(4,kv);
        break;
    case 5:
        emit this->sendMainMenuData(5,kv);
        break;
    case 0:
        F00(kv);
        break;
    case 7:
        F07(kv);
        break;
    }
}

void Task::F01(QMap<QString,QString> &kv)
{
    if(kv.value("logStatus")=="true")
        emit this->loginSucceed();
    else
        emit this->loginStatus(kv.value("reason"));
}

void Task::F02(QMap<QString, QString> &kv)
{
    emit this->sendMainMenuData(2,kv);
}

void Task::F03(QMap<QString, QString> &kv)
{
    qDebug()<<"F03:"<<kv<<endl;
    emit this->sendMainMenuData(3,kv);
}

void Task::F00(QMap<QString, QString> &kv)
{
    emit zhuCeStatus(kv.value("status")=="true"?true:false,kv.value("reason"));
}

void Task::F06(QMap<QString, QString> &kv)
{
    if(kv.value("isHave")=="true")
        emit this->loginStatus("用户存在预约服务");
    else
        emit this->loginStatus("密码修改失败");
}

void Task::F07(QMap<QString, QString> &kv)
{
    if(kv.value("isHave")=="true")
        emit this->loginStatus("请取消预约后再修改信息");
    else
        emit this->sendMainMenuData(7,kv);
}
